#pragma once

#include "GameEngine.h"
#include "WizardTrickState.h"

class WizardInitialState :
	public WizardTrickState
{
public:
	/*
		Game Initializer
	*/
	virtual
	GameState*		getNextSequence()
					{
						roundNumber = 0;

						auto const formerCount = playerCount;
						if (formerCount != (playerCount = GameEngine::instance().countParticipants()))
						{
							if (NULL == deck)
							{
								dealingSeat = rand() % playerCount;
								deck = WizardCard::generateDeck(LOSE_CARD, SPADES);
							} // end if: first game this runtime

							// Create the sequencer that advances a seat pointer around the table.
							delete[] NEXT_SEAT;
							NEXT_SEAT = new SeatNumber[playerCount];
							SeatNumber j = 0;
							for (auto i = playerCount; i--; j = i)
								NEXT_SEAT[i] = j;
							
							// Create a simple container for each round's bids.
							delete[] bidsBySeat;
							bidsBySeat = new CardNumber[playerCount];

							// Create the "running totals" for each player's score.
							delete[] startOfRoundScores;
							startOfRoundScores = new ExpectedValue[playerCount];
						} // end if: number of players changed since last game

						// Reset every player's score to the initial value, whatever it is.
						memset(startOfRoundScores, INITIAL_PLAYER_SCORE, sizeof(ExpectedValue) * playerCount);

						// Initial states always hand off preparation of the game root node
						// to a parent class, because the root node is merely a specialized
						// case of a round-starter.
						return WizardTrickState::getNextSequence();
					} // end method

	/*	Pattern: Singleton */
	static
	WizardInitialState*
	const			singleton()
					{
						return new WizardInitialState();
					} // end class method
}; // end class
